package z.thread;

public class Thread1 {
    public static void main(String[] args) {
        Shop shop=new Shop();
//        Thread t1=new Thread("范传奇"){
//            @Override
//            public void run() {
//                shop.buy();
//            }
//        };
//
//        Thread t2=new Thread("王克晶"){
//            @Override
//            public void run() {
//                shop.buy();
//            }
//        };
//        Runnable r1=new Runnable() {
//            @Override
//            public void run() {
//                shop.buy();
//            }
//        };
        //Thread t1=new Thread(r1);
//        Runnable r2=new Runnable() {
//            @Override
//            public void run() {
//                shop.buy();
//            }
//        };
//        Thread t2=new Thread(r2);

//        Runnable r1= () -> shop.buy();
//        Runnable r2= () -> shop.buy();
//        Thread t1=new Thread(r1);
//        Thread t2=new Thread(r2);

        Thread t1=new Thread(()->shop.buy());
        Thread t2=new Thread(()->shop.buy());
        t1.start();
        t2.start();
    }
}
class Shop{
    public void buy(){
        try {
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+"正在挑衣服...");
            Thread.sleep(5000);
            synchronized (this) {
                System.out.println(t.getName() + "正在试衣服...");
                Thread.sleep(5000);
            }
            System.out.println(t.getName()+"正在结账...");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
